<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<div id="openWin" class="easyui-window" inline="true" closed="true" iconCls="icon-save" style="width:500px;height:100px;padding:5px;">
	<div class="easyui-layout" fit="true">
		<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">

			<input type="hidden" name="subsidiaryId" id="subsidiaryId" />
			<table>
				<tr>
					<td align="right" style="vertical-align: top;"><label>名称</label></td>
					<td>
						<input type="text" name="name" id="name" class="easyui-validatebox" required="true" style="width: 120px;"/>
					</td>
				</tr>
				<tr>
					<td align="right" style="vertical-align: top;"><label>联系电话</label></td>
					<td>
						<input type="text" name="phone" id="phone" class="easyui-validatebox" style="width: 120px;" />
					</td>
				</tr>
				<tr>
					<td align="right" style="vertical-align: top;"><label>地址</label></td>
					<td>
						<input type="text" name="address" id="address" style="width: 120px;"/>
					</td>
				</tr>
				<tr>
					<td align="right" style="vertical-align: top;"><label>备注</label></td>
					<td>
						<textarea rows="3" cols="35" name="remark" id="remark"></textarea>
					</td>
				</tr>
			</table>
		</div>
		<div region="south" border="false" style="text-align:right;padding:5px 0;">
			<a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" onclick="save();">保存</a>
			<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)" onclick="$('#openWin').window('close');">关闭</a>
		</div>
	</div>
</div>

<script>

  function save() {
	  if ($('#name').validatebox('isValid')) {
		  $("#queryForm").submit();
	  }
  }
  
  function openAddForm() {
	  $("#subsidiaryId").val("");
	  
	  openWin('新建公司', 'subsidiary_addSubsidiaryAction.action');
  }
  
  function openWin(title, action) {
	  $("#queryForm").attr("action", action);
	  $('#openWin').window({
			title: title,
			modal: true,
			shadow: false,
			closed: false,
			collapsible: false,
			minimizable: false,
			maximizable: false,
			width: 450,
			height: 270
		});
  }
  
  function openModifyForm() {
	  
	  var rows = $('#dataTable').datagrid('getSelections');
	  if (rows.length <= 0) {
		  $.messager.alert('信息','请选择一条记录！','info');
		  return;
	  } else if (rows.length > 1) {
		  $.messager.alert('信息','只能选择一条记录！','info');
		  return;
	  }
	  
	  var url = "subsidiary_getSubsidiaryAction.action?subsidiaryId="+rows[0].subsidiaryId;
	  $.getJSON(url, function(data){
		  
		  if (data != null) {
			  $("#name").val(data.subsidiaryInfo.name);
			  $("#phone").val(data.subsidiaryInfo.phone);
			  $("#address").val(data.subsidiaryInfo.address);
			  $("#remark").val(data.subsidiaryInfo.remark);
			  $("#subsidiaryId").val(data.subsidiaryInfo.subsidiaryId);

			  openWin('修改公司', 'subsidiary_modifySubsidiaryAction.action');
		  }
		});
	}
    </script>